package com.shen.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;


import java.io.IOException;
import java.io.InputStream;

/**
 * Author:shen
 * CreateDate:2020/7/6.
 * Function:
 */
public class MybatisUtil {
    private static SqlSessionFactory factory;
    static {
        try {
            InputStream inputStream= Resources.getResourceAsStream("mybatisConfig.xml");
            factory=new SqlSessionFactoryBuilder().build(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public SqlSession getSqlSession(){
        return factory.openSession(true);
    }
}
